<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<meta HTTP-EQUIV="pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<meta HTTP-EQUIV="expires" CONTENT="0">
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragrma","no-cache");
response.setDateHeader("Expires",0);
%>
<title>_${customer.customerName}_执行拣货任务</title>
<script language="javascript" type="text/javascript" src="${ctx}/static/datepicker/WdatePicker.js"></script>
<script type="text/javascript">

  $(function() {
		$("#queryForm").validate(); 
		
		
  });
  
  
function ajaxGetPickCarStockInfo(){
	  
	  $("#btn_billup_car").attr("disabled",true);
	  $("#btn_billup_car").attr("class","btn");
	  $("#stockInfo_car").html('');
	  $("#car_msg").html('');
	  var orderNum="${task.orderQty}";
	  var carId=$("#sel_carId").val();
	  var customerCode='${customer.customerCode}';
	  var warehouseCode='${task.warehouseCode}';
	  
	  $.ajax({
			type : 'post',
			url : '${ctx}/pickTask/ajaxGetPickCarStockInfo',
			data : {
				customerCode:customerCode,
				warehouseCode:warehouseCode,
				carId:carId,
				taskCode:'${task.taskCode}'
			},
			dataType : 'json',
			success : function(data) {
				
				var car=data.car;
				if(car.status=='busy'){
					$("#car_msg").html("使用中，请选择其他推车!");
				}else if(car.stockNum < orderNum ){
					$("#car_msg").html("架位数不能满足此任务,请选择其他推车!");
				}else{
					$("#btn_billup_car").attr("disabled",false);
					$("#btn_billup_car").attr("class","btn btn-primary");
					
					var stockList = data.stockList;
					var str="";
					$.each(stockList, function(i,stock) {
					    
					    str +="<tr name='tr_stock_car' >";
					    str += "<td id='stockCode_car_"+stock.stockCode+"'>"+stock.stockCode+"</td>";
						str += "<td id='stockName_car_"+stock.stockCode+"'>" +stock.stockName+ "</td>";
						
						var status=stock.status;
						if(status=='free'){
						  str += "<td name='status_car' id="+stock.stockCode+">空置中</td>";
						}else if(status=='busy'){
						  str += "<td name='status_car' id="+stock.stockCode+">使用中</td>";
						}
						
						str += "<td name='orderno_car' id='orderno_car_"+stock.stockCode+"'></td>";
						str += "<td id='goodsNum_car_"+stock.stockCode+"'></td>";
						str += "<td id='goodsInfo_car_"+stock.stockCode+"'></td>";
						
						str +="</tr>";
					});
					$("#stockInfo_car").html(str);
				}
				
				var orderList=data.orderList;
				$.each(orderList,function(i,order){
					
					 $("[name='status_car']").each(function(){
			    		 var status=$(this).html();
			    		 if(status=='空置中'){
			               var stockCode=(i+1);
			               $("#orderno_car_"+stockCode).html(order.order.ordeno); 
			               
			               var goodsNum=0;
			               var goodsInfo='';
			               $.each(order.order.orderItems,function(j,orderItem){
			            	   goodsNum+=orderItem.qty;
			            	   goodsInfo+=orderItem.sku+"_"+orderItem.qty+";"
			               });
			               
			               $("#goodsNum_car_"+stockCode).html(goodsNum);
			               $("#goodsInfo_car_"+stockCode).html(goodsInfo);
			               $(this).html("使用");
			               return false;
			    		 }
			    	 });
		    		
		    	 });
				
				
			},
			error:function() {
				alert("网络繁忙，请稍后重试...");
			}
		}); 
		
  }
  
  //获取拣货信息
  function getInfo(stockInfo,part,sku) {
      
       var stockInfoArray=stockInfo.split(";");
       var stockInfo="";
       
       for(var i=0;i<stockInfoArray.length;i++){
          var info=stockInfoArray[i];
          if(info.indexOf(sku)!=-1){
             stockInfo=info;
             break;
          }
       }
       
       var infoArray=stockInfo.split("_");
       
       var temp='';
       if( part=='sku' ){
          temp=infoArray[2];
       }else if(part=='stockCode'){
         temp=infoArray[0];
       }else if(part=='num'){
         temp=infoArray[3];
       }else if(part=='boxCode'){
         temp=infoArray[1];
       }
       return temp;
	}
  
   //完成拣货任务
   function completePick(taskId){
	   
	   $("#btn_complete").attr("disabled", true);
	   
	   var boxCode=$("#txt_boxCode").val().trim();
	   if(boxCode==""){
		   alert("请输入箱子编码...");
		   $("#btn_complete").attr("disabled", false);
		   $("#txt_boxCode").focus();
		   return;
	   }
	   
       $.ajax({
			type:'post',
			url:'${ctx}/pickTask/ajaxCompletePickTask',
			data:{
				taskId:taskId,
				boxCode:boxCode
			},
			dataType:'json',
			success:function(data) {
			    if(data==true){
			      alert("此任务已完成拣货！");
			      
			      $("#btn_complete").attr("disabled", true);
			      $("#btn_complete").attr("class", "btn");
			      $("#btn_close").trigger("click");
			      location.reload();
				  
			    }else{
			      $("#btn_complete").attr("disabled", false);
			      alert("网络繁忙，请稍后重试...");
			    }
			},
			error:function() {
				$("#btn_complete").attr("disabled", false);
				alert("网络繁忙，请稍后重试...");
			}
	   });
       
   }
   
</script>
</head>

<body>

<section class="content">
<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-edit"></i>
					<h3 class="box-title">任务信息</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">

	<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
<!-- 		<thead> -->
<!-- 			<th style="vertical-align: middle; color: white; " colspan="12" bgcolor="#8EB4CB">任务信息</th> -->
<!-- 		</thead> -->
		<thead><tr>
		        <th>商家</th>
		        <th>仓库</th>
			    <th>任务编号</th>
			    <th>订单类型</th>
			    <th>运单类型</th>
			    <th>作业类型</th>
			    <th>批次编号</th>
			    <th>订单数量（条）</th>
			    <th>任务状态</th>
			    <th>操作</th>
			</tr>
	   </thead>
	   <tr>
	      <td>${task.customerCode}</td>
	      <td>${task.warehouseCode}</td>
	      <td>${task.taskCode}</td>
	      <td>
	        <c:if test="${task.pickType eq 'single'}">单件</c:if>
	        <c:if test="${task.pickType eq 'multi'}">多件
	          <c:if test="${task.pickModel eq 'lamp'}"><font color=blue>【灯光拣选】</font></c:if>
			  <c:if test="${task.pickModel eq 'car'}"><font color=red>【推车拣选】</font></c:if>
			  <c:if test="${t.pickModel eq 'normal'}"><font color=blue>【普通拣选】</font></c:if>
	        </c:if>
	      </td>
	      <td>
	          <c:if test="${task.billType eq 'cbill'}">普通运单</c:if>
			  <c:if test="${task.billType eq 'ebill'}">电子运单</c:if>
	      </td>
	      <td>
			     <c:if test="${task.flowType eq 'prePrint'}">预先打单</c:if>
			     <c:if test="${task.flowType eq 'intimePrint'}">及时打单</c:if>
		  </td>
	      <td>${task.batchCode}</td>
	      <td>${task.orderQty}</td>
	      <td>
             <!-- 任务状态( 1.创建任务 2.已分配拣货任务  3.已拣货  4. 已分配灯光拣选任务  5.已经灯光拣选  6.已分配包装任务  7.已包装  8.已分配发货任务  9.已发货  10.灯光拣选进行中..) -->
			     <c:if test="${task.status eq '1'}"><font color=blue>创建任务</font></c:if>
			     <c:if test="${task.status eq '2'}"><font color=blue>已分配拣货任务</font></c:if>
			     <c:if test="${task.status eq '3'}"><font color=blue>已拣货</font></c:if>
			     <c:if test="${task.status eq '4'}"><font color=blue>已分配灯光拣选任务</font></c:if>
			     <c:if test="${task.status eq '5'}"><font color=blue>已经灯光拣选</font></c:if>
			     <c:if test="${task.status eq '6'}"><font color=blue>已分配包装任务</font></c:if>
			     <c:if test="${task.status eq '7'}"><font color=blue>已包装</font></c:if>
			     <c:if test="${task.status eq '8'}"><font color=blue>已分配发货任务</font></c:if>
			     <c:if test="${task.status eq '9'}"><font color=blue>已发货</font></c:if>
			     <c:if test="${task.status eq '10'}"><font color=blue>灯光拣选中..</font></c:if>
			     <c:if test="${task.status eq '11'}"><font color=blue>推车拣选中..</font></c:if>
			     <c:if test="${task.status eq '12'}"><font color=blue>拣选中..</font></c:if>
	     </td>
	      <td>
	          <a href="${ctx}/pickTask/v2_toPrintPickInfo_multi/${task.taskCode}"  role="button" class="btn btn-primary" >导出拣货单</a>

			  <c:if test="${task.pickModel eq 'car'}">
				  <c:if test="${task.status eq '2'}">
				       <a href="${ctx}/carPickTask/v2_toCarPickTaskPage/${task.id}" role="button" data-toggle="modal" class="btn btn-primary" >推车拣选</a>
			     </c:if>
			     <c:if test="${task.status eq '11'}">
			           <a href="${ctx}/carPickTask/v2_toCarPickTaskPage/${task.id}" role="button" data-toggle="modal" class="btn btn-primary" >继续拣选</a>
			     </c:if>
			     <c:if test="${task.status ne '2' and task.status ne '11'}">
	                <input type="button" value="已完成推车拣选" class="btn"  disabled="disabled">
	             </c:if>
			  </c:if>
			  
			  <c:if test="${task.pickModel eq 'lamp'}">
		          <c:if test="${task.status eq '2'}">
		            <a href="${ctx}/pickTask/v2_toPickPage/${task.taskCode}" id="btn_complete_1" class="btn btn-primary">拣货</a>
<!-- 		            <a href="#boxCodeWindow" id="btn_complete"  role="button" class="btn btn-primary" data-toggle="modal">一键拣货</a> -->
		          </c:if>
		           <c:if test="${task.status eq '12'}">
		            <a href="${ctx}/pickTask/v2_toPickPage/${task.taskCode}" id="btn_complete_1" class="btn btn-primary">继续拣货</a>
		          </c:if>
		          <c:if test="${task.status ne '2' and task.status ne '12'}">
		            <input type="button" value="已完成拣货" class="btn" id="btn_print" disabled="disabled">
		          </c:if>
		      </c:if>
		      
		       <c:if test="${task.pickModel eq 'normal'}">
		          <c:if test="${task.status eq '2'}">
		            <a href="${ctx}/pickTask/v2_toPickPage/${task.taskCode}" id="btn_complete_1" class="btn btn-primary">拣货</a>
<!-- 		            <a href="#boxCodeWindow" id="btn_complete"  role="button" class="btn btn-primary" data-toggle="modal">一键拣货</a> -->
		          </c:if>
		           <c:if test="${task.status eq '12'}">
		            <a href="${ctx}/pickTask/v2_toPickPage/${task.taskCode}" id="btn_complete_1" class="btn btn-primary">继续拣货</a>
		          </c:if>
		          <c:if test="${task.status ne '2' and task.status ne '12'}">
		            <input type="button" value="已完成拣货" class="btn" id="btn_print" disabled="disabled">
		          </c:if>
		      </c:if>
	          
	      </td>
	   </tr>
	</table>
	
	</div></div></div></div>
	
	<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-edit"></i>
					<h3 class="box-title">订单信息</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
				
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
<!-- 	    <thead> -->
<!-- 			<th style="vertical-align: middle; color: white; " colspan="11" bgcolor="#8EB4CB">订单信息</th> -->
<!-- 		</thead> -->
		<thead><tr>
			    <th>序号</th>
			    <th>订单编号</th>
			    <th>SKU编号</th>
			    <th>数量</th>
			</tr></thead>
		<tbody>
		<c:forEach items="${orderList}" var="o" varStatus="i">
		
		   <c:forEach items="${o.order.orderItems}" var="orderItem" varStatus="j">
			<tr>
			   <td>${i.count}-${j.count}</td>
			   <td>${o.order.ordeno}</td>
			   <td>${orderItem.sku}</td>
			   <td>${orderItem.qty}</td>
			</tr>
			</c:forEach>
			
		</c:forEach>
		</tbody>
	</table>
	</div></div></div></div>
	
	
				
	 <!-- 录入箱子编码 窗体 --> 
	<div  class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" id="boxCodeWindow">
		<div class="modal-body">
			
			<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
			<thead>
				<th style="vertical-align: middle; color: white; height: 30px;" colspan="12" bgcolor="#8EB4CB">录入箱子编码</th>
			</thead>
		   <tr>
		      <td style="text-align: center; height: 100px; vertical-align: middle;">
		       <input type="text" id="txt_boxCode"/>
		      </td>
		   </tr>
		</table>
			
		</div>
		<div class="modal-footer">
		  <input type="button" value="完成" class="btn btn-primary"  onclick="completePick('${task.id}');">
		  <button id="btn_close" class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
		</div>
	</div>
	
	
</section>

</body>
</html>
